<!--代码逻辑和样式库-->
<script src="./role-manage.component.js"></script>
<style src="./role-manage.scss" scoped lang="scss"></style>

<template>
  <div>
    <!-- 操作按钮 -->
    <!-- 搜索区域 -->
    <div v-if="codesCheck.indexOf('Query') !== -1" class="search-container">
      <el-form label-position="top">
        <el-row type="flex">
          <el-col :span="24" class="aq-vertical-middle">
            <el-input v-if="codesCheck.indexOf('Query') !== -1" v-model="queryString" placeholder="请输入角色名" class="keyword" clearable @keyup.enter.native="searchRoles()" />
            <el-button v-waves v-if="codesCheck.indexOf('Query') !== -1" type="primary" icon="el-icon-search" class="aq-margin-left-4" @click="searchRoles()">
              查询
            </el-button>
            <el-button v-waves v-if="codesCheck.indexOf('Query') !== -1" type="warning" icon="el-icon-refresh" @click="resetRoles()">
              重置
            </el-button>
            <el-button v-waves v-if="codesCheck.indexOf('Create') !== -1" type="success" icon="el-icon-edit" @click="openEditRoleDetailDialog('create')">
              创建
            </el-button>
            <el-button v-waves v-if="codesCheck.indexOf('Delete') !== -1" type="danger" icon="el-icon-delete" @click="deleteSelectedRole()">
              批量删除
            </el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 内容区域 -->
    <div class="content-container aq-margin-top-16">
      <!--用户角色table-->
      <el-table v-loading="loading" :data="dataList" border fit highlight-current-row @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" fixed></el-table-column>
        <el-table-column prop="name" label="角色名称">
          <template slot-scope="scope">
            <el-button v-if="codesCheck.indexOf('Edit') != -1" type="text" @click="openEditRoleDetailDialog('edit', scope.row)">{{ scope.row.name }}</el-button>
            <span v-if="codesCheck.indexOf('Edit') == -1">{{ scope.row.name }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="code" label="角色Code" />
        <el-table-column prop="description" label="说明" />
        <el-table-column prop="userName" label="成员" />
        <el-table-column label="操作" align="center" width="180">
          <template slot-scope="scope">
            <el-button v-if="codesCheck.indexOf('Edit') !== -1" size="mini" type="success" @click="openSettingRoleDialog(scope.row)">人员</el-button>
            <el-button v-if="codesCheck.indexOf('Edit') !== -1" size="mini" type="warning" @click="openSettingCodeDialog(scope.row)">权限</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页插件 -->
      <!-- <pagination v-show="totalNum > 0" :total="totalNum" :page.sync="pageNum" :limit.sync="recordNum" @pagination="getRoleList" /> -->
    </div>
    <!-- 创建/编辑角色 -->
    <el-dialog :title="dialogTitle" :visible.sync="editDialogVisible" width="500px">
      <el-form ref="dataForm" :model="roleEditForm" :rules="roleEditRules" label-position="top">
        <el-row :gutter="20">
          <el-col :xs="24" :sm="24" :lg="24">
            <el-form-item prop="name" label="角色名称:" label-width="110px">
              <el-input v-model="roleEditForm.name" class="el-input-width" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="24">
            <el-form-item prop="code" label="角色code:" label-width="110px">
              <el-input v-model="roleEditForm.code" class="el-input-width" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="24">
            <el-form-item label="角色说明:" label-width="110px">
              <el-input v-model="roleEditForm.description" class="el-input-width" />
            </el-form-item>
          </el-col>
          <el-col v-if="roleEditForm.type == 'edit'" :xs="24" :sm="24" :lg="24">
            <el-form-item label="属下管理员:" label-width="110px">
              <span>{{ roleEditForm.userName }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="24" :lg="24" align="right">
            <el-button type="primary" class="action-btn" @click="save()">确定</el-button>
            <el-button class="action-btn" @click="editDialogVisible = false">取消</el-button>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
    <!-- 分配人员 -->
    <el-dialog :visible.sync="settingRoleDialogVisible" title="分配人员" width="800px" class="settingUser">
      <el-input v-model="userQueryString" placeholder="请输入用户名，姓名" class="filter-item keyword" @keyup.enter.native="checkChange()" />
      <!-- 操作按钮 -->
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="checkChange()">
        查询
      </el-button>
      <el-button v-waves class="filter-item" type="warning" icon="el-icon-refresh" @click="resetSearchUserWithKeyword()">
        重置
      </el-button>
      <el-button v-waves class="filter-item float-right" type="success" icon="el-icon-edit" @click="saveAssignedUsers()">
        保存
      </el-button>
      <el-row :gutter="20" class="user-container" type="flex">
        <el-col :sm="7" :md="7" :lg="7" class="left-container scroll-menu-container">
          <el-tree ref="departmentTree" :data="departmentTreeList" :props="departmentProps" :default-checked-keys="departmentTreeList" node-key="id" default-expand-all highlight-current @node-click="searchUsersWithSelectedDepartment">
            <span slot-scope="{ node }" class="custom-tree-node">
              <i class="el-icon-document" />
              <span class="">{{ node.label }}</span>
            </span>
          </el-tree>
        </el-col>
        <el-col :sm="17" :md="17" :lg="17" class="right-container">
          <el-table v-loading="loading" ref="userTable" :data="userList" highlight-current-row @selection-change="selectedUserChange" @select="checkUser()">
            <el-table-column prop="trueName" label="姓名" align="center" />
            <el-table-column prop="mobileNumber" label="电话" align="center" />
            <el-table-column label="添加" type="selection" width="60" align="center" />
          </el-table>
          <!-- <pagination v-show="userTotalNum > 0" :total="userTotalNum" :page.sync="userPageNum" :limit.sync="recordNum" @pagination="searchUsers" /> -->
        </el-col>
      </el-row>
    </el-dialog>
    <!-- 分配权限 -->
    <el-dialog :visible.sync="settingCodesDialogVisible" title="权限配置" width="800px" class="settingUser">
      <el-row :gutter="20">
        <el-col :span="24" align="right">
          <el-button v-waves :disabled="selectedMenuId == ''" type="success" icon="el-icon-edit" @click="saveAssignedCodes()">
            保存
          </el-button>
        </el-col>
      </el-row>
      <el-row :gutter="20" class="user-container" type="flex">
        <el-col :sm="7" :md="7" :lg="7" class="left-container scroll-menu-container">
          <el-tree ref="menuTree" :data="menuTreeList" :props="routeProps" :default-checked-keys="menuTreeList" node-key="id" default-expand-all highlight-current @node-click="searchCodesWithSelectedMenu">
            <span slot-scope="{ node }" class="custom-tree-node">
              <i class="el-icon-document" />
              <span class="">{{ node.label }}</span>
            </span>
          </el-tree>
        </el-col>
        <el-col :sm="17" :md="17" :lg="17" class="right-container">
          <el-table v-loading="loading" ref="menuTable" :data="codes" highlight-current-row @selection-change="selectedUserChange" @select="checkUser()">
            <el-table-column prop="name" label="名称" align="center" />
            <el-table-column prop="permission" label="操作码" align="center" />
            <el-table-column label="添加" type="selection" width="60" align="center" />
          </el-table>
        </el-col>
      </el-row>
    </el-dialog>
  </div>
</template>
